package net.joint_painting.client.observer;

import java.util.LinkedList;
import java.util.List;

/**
 * @author CAM
 * @version $Revision: 1.0 $
 */
public class ViewObserverListener {

    /**
     * Method singleton.
     * 
     * @return ViewObserverListener
     */
    public static ViewObserverListener singleton() {
	if (singleton == null)
	    singleton = new ViewObserverListener();
	return singleton;
    }

    List<ViewObserver> observers = new LinkedList<ViewObserver>();

    static ViewObserverListener singleton;

    public ViewObserverListener() {

    }

    /**
     * Method attach.
     * 
     * @param observer
     *            ViewObserver
     */
    public void attach(ViewObserver observer) {
	observers.add(observer);
    }

    /**
     * Method detach.
     * 
     * @param observer
     *            ViewObserver
     */
    public void detach(ViewObserver observer) {
	observers.remove(observer);
    }

    /**
     * Method notify.
     * 
     * @param object
     *            ViewObject
     */
    public void notify(ViewObject object) {
	for (int i = 0; i < observers.size(); i++) {
	    observers.get(i).update(object);
	}
    }

}
